<template>
  <div class="Discoverylist">
    <div id="header">
      <i class="iconfont icon-fanhui i" @click.stop="$router.back()"></i>
      <h1>{{ $route.query.title }}</h1>
    </div>
    <div class="nav">
      <li
        v-for="(item, index) in Discoverylist.children"
        :key="item.id"
        :class="{ active: active == index }"
        @click="
          active = index;
          discoveryde(item);
        "
      >
        <span>{{ item.name }}</span>
      </li>
    </div>

    <div class="vanlist" v-if="!show">
      <div class="screen">
        <h1>筛选</h1>
      </div>
      <div class="navs">
        <li
          v-for="(item, index) in Discoverylist.children"
          :key="item.id"
          :class="{ active: active == index }"
          @click="
            active = index;
            discoveryde(item);
          "
        >
          <span>{{ item.name }}</span>
        </li>
      </div>
    </div>

    <div class="mask" v-if="!show"></div>

    <div class="more" @click="showPopup">
      <i class="iconfont icon-gengduo" v-if="show"></i>
      <i class="iconfont icon-cuocha_kuai" v-else></i>
    </div>
    <div class="components">
      <DiscoveryDetails :discoverydetails="discoverydetails" />
    </div>
  </div>
</template>

<script>
import DiscoveryDetails from "../components/ViewDiscovery/DiscoveryDetails.vue";
export default {
  components: { DiscoveryDetails },
  data: function () {
    return {
      Discoverylist: [],
      discoverydetails: [],
      show: true,
      active: 0,
    };
  },
  created: function () {
    this.axios.get("https://apis.netstart.cn/xpc/search/config").then((res) => {
      for (let i = 0; i < res.data.data.category.length; i++) {
        if (res.data.data.category[i].id == this.$route.query.id) {
          this.Discoverylist = res.data.data.category[i];
        }
      }
    });
    this.axios
      .get(
        "https://apis.netstart.cn/xpc/articles?category_id=" +
          this.$route.query.id
      )
      .then((res) => {
        this.discoverydetails = res.data.data;
      });
  },
  methods: {
    showPopup() {
      this.show = !this.show;
    },
    discoveryde(item) {
      this.axios
        .get("https://apis.netstart.cn/xpc/articles?category_id=" + item.id)
        .then((res) => {
          this.discoverydetails = res.data.data;
        });
    },
  },
};
</script>

<style lang="less" scoped>
.Discoverylist {
  position: relative;

  .i {
    position: absolute;
    left: 20px;
    top: 12px;
    font-weight: bold;
    font-size: 17px;
  }
  #header {
    display: flex;
    justify-content: center;
    // margin: 10px 0;
    padding-top: 10px;
    padding-bottom: 20px;
    border-bottom: 1px solid #bebebe;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    background-color: white;
    h1 {
      font-weight: bold;
    }
  }
  .nav {
    position: fixed;
    top: 50px;
    background-color: white;
    padding: 10px 0;
    display: flex;
    width: 90%;
    z-index: 999;
    white-space: nowrap;
    overflow: auto;
    border-bottom: 1px solid #d0d0d0;
    &::-webkit-scrollbar {
      display: none;
    }
    li {
      flex-shrink: 0;
      list-style: none;
      background-color: #d0d0d0;
      height: 30px;
      border-radius: 5px;
      margin: 0 5px;
      &:nth-of-type(1) {
        margin-left: 20px;
      }
      span {
        margin: 0 15px;
        line-height: 30px;
        font-size: 13px;
        color: gray;
      }
    }
    .active {
      span {
        color: red;
      }
    }
  }
  .vanlist {
    padding-bottom: 20px;
    max-height: 50vh;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background-color: white;
    .screen {
      padding-bottom: 10px;
      border-bottom: 1px solid #bebebe;
      h1 {
        font-weight: bold;
        margin: 0 20px;
      }
    }
    .navs {
      display: flex;
      width: 100%;
      flex-wrap: wrap;
      padding-left: 20px;
      padding-top: 20px;
      li {
        flex-shrink: 0;
        list-style: none;
        background-color: #d0d0d0;
        height: 30px;
        border-radius: 5px;
        margin: 5px;
        span {
          margin: 0 15px;
          line-height: 30px;
          font-size: 13px;
          color: gray;
        }
      }
      .active {
        span {
          color: red;
        }
      }
    }
  }
  .mask {
    height: 86vh;
    background-color: rgba(32, 32, 32, 0.3);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: -1;
  }
  .more {
    height: 51px;
    width: 10%;
    position: fixed;
    top: 50px;
    right: 0;
    background-color: white;
    text-align: center;
    line-height: 51px;
    border-bottom: 1px solid #d0d0d0;
    i {
      font-size: 24px;
    }
  }
  .components{
    margin-top: 113px;
  }
}
</style>